﻿#include "ui_dns.h"
#include "ui_ui_dns.h"
#include <QMessageBox>

uiDna::uiDna(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::uiDns)
{
    ui->setupUi(this);

    this->m_xml = new ToolXml;

    ui->bg->setCurrentIndex(0);
}

uiDna::~uiDna()
{
    delete ui;
    delete m_xml;
}

void uiDna::on_pushButton_clicked()
{
    ui->bg->setCurrentIndex(1);
}

void uiDna::on_pushButton_3_clicked()
{
    ui->bg->setCurrentIndex(0);
}

void uiDna::on_pushButton_2_clicked()
{
    qDebug() << "设置dns";
    LocalDev local = *m_ld;
    localDna_t dns;

    bool ok;
    bool ret = true;

    dns.m_01 = ui->e_1->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_02 = ui->e_2->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_03 = ui->e_3->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_04 = ui->e_4->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_05 = ui->e_5->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_06 = ui->e_6->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_07 = ui->e_7->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_08 = ui->e_8->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_09 = ui->e_9->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_10 = ui->e_10->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_11 = ui->e_11->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_12 = ui->e_12->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_13 = ui->e_13->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_14 = ui->e_14->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_21 = ui->e_21->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_22 = ui->e_22->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_23 = ui->e_23->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_24 = ui->e_24->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_25 = ui->e_25->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.m_26 = ui->e_26->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.latitude = ui->eLatitude->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.longitude = ui->eLongitude->text().toFloat(&ok);
    ret = ok ? ret : ok;
    dns.elevation = ui->eElevation->text().toFloat(&ok);
    ret = ok ? ret : ok;

    if (!ret)
    {
        QMessageBox::information(this, "参数错误", "输入的参数有误！");
        return;
    }

    local.setDna(dns);

    QString xml = m_xml->makeSetDnaXml(&local);

    emit setDna(xml);
}

void uiDna::refrDna(LocalDev *ld)
{
    this->m_ld = ld;

    localDna_t dns = ld->getDna();
    ui->m_1->setText(QString::number(dns.m_01));
    ui->m_2->setText(QString::number(dns.m_02));
    ui->m_3->setText(QString::number(dns.m_03));
    ui->m_4->setText(QString::number(dns.m_04));
    ui->m_5->setText(QString::number(dns.m_05));
    ui->m_6->setText(QString::number(dns.m_06));
    ui->m_7->setText(QString::number(dns.m_07));
    ui->m_8->setText(QString::number(dns.m_08));
    ui->m_9->setText(QString::number(dns.m_09));
    ui->m_10->setText(QString::number(dns.m_10));
    ui->m_11->setText(QString::number(dns.m_11));
    ui->m_12->setText(QString::number(dns.m_12));
    ui->m_13->setText(QString::number(dns.m_13));
    ui->m_14->setText(QString::number(dns.m_14));
    ui->m_21->setText(QString::number(dns.m_21));
    ui->m_22->setText(QString::number(dns.m_22));
    ui->m_23->setText(QString::number(dns.m_23));
    ui->m_24->setText(QString::number(dns.m_24));
    ui->m_25->setText(QString::number(dns.m_25));
    ui->m_26->setText(QString::number(dns.m_26));
    ui->latitude->setText(QString::number(dns.latitude));
    ui->longitude->setText(QString::number(dns.longitude));
    ui->elevation->setText(QString::number(dns.elevation));

    ui->e_1->setText(QString::number(dns.m_01));
    ui->e_2->setText(QString::number(dns.m_02));
    ui->e_3->setText(QString::number(dns.m_03));
    ui->e_4->setText(QString::number(dns.m_04));
    ui->e_5->setText(QString::number(dns.m_05));
    ui->e_6->setText(QString::number(dns.m_06));
    ui->e_7->setText(QString::number(dns.m_07));
    ui->e_8->setText(QString::number(dns.m_08));
    ui->e_9->setText(QString::number(dns.m_09));
    ui->e_10->setText(QString::number(dns.m_10));
    ui->e_11->setText(QString::number(dns.m_11));
    ui->e_12->setText(QString::number(dns.m_12));
    ui->e_13->setText(QString::number(dns.m_13));
    ui->e_14->setText(QString::number(dns.m_14));
    ui->e_21->setText(QString::number(dns.m_21));
    ui->e_22->setText(QString::number(dns.m_22));
    ui->e_23->setText(QString::number(dns.m_23));
    ui->e_24->setText(QString::number(dns.m_24));
    ui->e_25->setText(QString::number(dns.m_25));
    ui->e_26->setText(QString::number(dns.m_26));
    ui->eLatitude->setText(QString::number(dns.latitude));
    ui->eLongitude->setText(QString::number(dns.longitude));
    ui->eElevation->setText(QString::number(dns.elevation));
}
